#include "PakEngine.h"
#include "DrawObject.h"
#include "RenderList.h"
#include "Physics.h"
#include "stdio.h"


Sprite::Sprite (int tx, int ty , int tz, char *cad)
{
	RestoreToDefaults();
	SetGraf(cad);
	MoveTo(tx,ty,tz);
	SetVisible(true);
}

Sprite::Sprite(void)
{
	RestoreToDefaults();
}

Sprite::~Sprite(void)
{
}

	//Seters
void Sprite::SetGraf(int id)
{
	graf = id;
}

void Sprite::SetGraf(char *cad)
{
	graf = PAKENGINE_LoadGraph(cad);
}

void Sprite::Move(int incx, int incy)
{
	x += incx;
	y += incy;
}

void Sprite::Move(int incx, int incy, int incz)
{
	x += incx;
	y += incy;
	z += incz;
}

void Sprite::MoveTo(int tx, int ty)
{
	x = tx;
	y = ty;
	z = 0;
}

void Sprite::MoveTo(int tx, int ty, int tz)
{
	x = tx;
	y = ty;
	z = tz;
}

void Sprite::Rotate(float inc_angle)
{
	angle += inc_angle;
}

void Sprite::RotateTo(float tangle)
{
	angle = tangle;
}

void Sprite::Escale(float inc_escale)
{
	escale += inc_escale;
}

void Sprite::EscaleTo(float tescale)
{
	escale = tescale;
}

void Sprite::FlipX(void)
{
	flipx = !flipx;
}

void Sprite::FlipY(void)
{
	flipy = !flipy;
}

void Sprite::FlipXY(void)
{
	Sprite::FlipX();
	Sprite::FlipY();
}

void Sprite::RestoreToDefaults(void)
{
	x = 0;
	y = 0;
	z = 0;
	angle = 0.0;
	escale = 100.0;
	flipx = false;
	flipy = false;
	visible = false;
	graf = 0;
}

void Sprite::Push(void)
{
}

void Sprite::Pop(void)
{
}

void Sprite::SetVisible(bool tvisible)
{
	visible = tvisible;
}

	//Geters
int Sprite::GetX(void)
{
	return x;
}

int Sprite::GetY(void)
{
	return y;
}

int Sprite::GetZ(void)
{
	return z;
}

int Sprite::GetGraf(void)
{
	return graf;
}

float Sprite::GetAngle(void)
{
	return angle;
}

float Sprite::GetEscale(void)
{
	return escale;
}

bool Sprite::IsFlippedinX(void)
{
	return flipx;
}

bool Sprite::IsFlippedinY(void)
{
	return flipy;
}

bool Sprite::IsVisible(void)
{
	return visible;
}

void Sprite::Draw(void)
{
	if(visible)
		RENDERLIST_Insert(new DrawObject(x,y,z,graf,angle,escale,flipx,flipy));
}

int Sprite::IsNotInside(Sprite *other)
{
	return PHYSICS_NotInside(this->GetX(), this->GetY() , this->GetGraf(),   other->GetX(), other->GetY() , other->GetGraf() );
}

int Sprite::CollisionWith(Sprite *other)
{
	return PHYSICS_Collision(this->GetX(), this->GetY() , this->GetGraf(),   other->GetX(), other->GetY() , other->GetGraf() );
}